import { createApp } from 'vue';
import '@/styles/main.scss';
import VueAnimXyz from '@animxyz/vue3';
import '@animxyz/core';
import ElementPlus from 'element-plus';
import 'element-plus/dist/index.css';
import App from './App.vue';
import { createPinia } from 'pinia';
import piniaPluginPersistedstate from 'pinia-plugin-persistedstate';
import router from './router/route';
import SvgIcon from '@/components/SvgIcon.vue';
import { setupDirectives } from '@/directive';
import Vant from 'vant';
import 'vant/lib/index.css';
import { Icon } from 'vant';
// 根据环境变量决定是否启用 VConsole
if (import.meta.env.VITE_ENABLE_VCONSOLE === 'true') {
  import('vconsole').then((module) => {
    const VConsole = module.default;
    new VConsole();
  });
}

// 全局引入 VueCropper
import VueCropper from 'vue-cropper';
import 'vue-cropper/dist/index.css';
// 按需引入
// import { Button, Popup } from 'vant';
import { Locale } from 'vant';
// 引入英文语言包
import enUS from 'vant/es/locale/lang/en-US';
Locale.use('en-US', enUS);
const app = createApp(App);
// app.use(Button);
// app.use(Popup);
app.use(Vant);
app.use(VueCropper);
// 注册自定义指令
setupDirectives(app);

// 注册Element Plus
app.use(ElementPlus);
app.use(Icon);

// 全局组件注册
import FloatActions from '@/components/FloatActions.vue';
import { registerIcons } from './components/icons';
import { initOrderPolling } from './utils/initOrderPolling';
app.component('FloatActions', FloatActions);

app.component('SvgIcon', SvgIcon);
registerIcons(app);

const pinia = createPinia();
// 注册持久化插件
pinia.use(piniaPluginPersistedstate);

app.use(router).use(pinia).use(VueAnimXyz).mount('#app');

// 初始化订单轮询
initOrderPolling();
